package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"github.com/jinzhu/gorm"
	"meonu/models"
)

type MeonuController struct {
	beego.Controller
}
type Response struct {
	Data    interface{}
	Code    string
	Message string
}

func (c *MeonuController) Update() {
	id, _ := c.GetInt("id")
	Name := c.GetString("Name")
	menu := models.Meon{
		Model: gorm.Model{ID: uint(id)},
		Name:  Name,
	}
	err := models.Update(menu)
	if err != nil {
		c.Data["json"] = Response{nil, "500", "修改失败"}
		c.ServeJSON(true)
	}
	c.Data["json"] = Response{nil, "500", "修改成功"}
	c.ServeJSON(true)
}
func (c *MeonuController) Del() {
	id, _ := c.GetInt("id")
	men := models.Meon{
		Model: gorm.Model{ID: uint(id)},
	}
	err := models.Del(men)
	if err != nil {
		c.Data["json"] = Response{nil, "500", "删除失败"}
		c.ServeJSON(true)
	}
	c.Data["json"] = Response{nil, "500", "删除成功"}
	c.ServeJSON(true)
}
